package com.huike.controller.system;

import com.huike.common.annotation.Log;
import com.huike.common.enums.BusinessType;
import com.huike.controller.core.BaseController;
import com.huike.domain.common.AjaxResult;
import com.huike.domain.system.SysNotice;
import com.huike.page.TableDataInfo;
import com.huike.service.ISysNoticeService;
import com.huike.web.CurrentUserHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 通知公告 信息操作处理
 */
@Api(tags = "系统管理")
@RestController
@RequestMapping("/system/notice")
public class SysNoticeController extends BaseController {
    @Autowired
    private ISysNoticeService noticeService;

    /**
     * 获取通知公告列表
     */
    @ApiOperation("通知公告-列表查询")
    // @PreAuthorize("system:notice:pagelist")
    @GetMapping("/pagelist/{status}")
    public TableDataInfo pagelist(@PathVariable String status) {
        startPage();
        List<SysNotice> list = noticeService.selectNoticeList(CurrentUserHolder.getUserId(), status);
        return getDataTable(list);
    }

    @ApiOperation("通知公告-获取系统提醒下拉列表")
    // @PreAuthorize("system:notice:list")
    @GetMapping("/list/{status}")
    public AjaxResult list(@PathVariable String status) {
        List<SysNotice> list = noticeService.selectNoticeList(CurrentUserHolder.getUserId(), status);
        return AjaxResult.success(list);
    }

    /**
     * 根据通知公告编号获取详细信息
     */
    @ApiOperation("通知公告-获取详情信息")
    // @PreAuthorize("system:notice:query")
    @GetMapping(value = "/{noticeId}")
    public AjaxResult getInfo(@PathVariable Long noticeId) {
        return AjaxResult.success(noticeService.selectNoticeById(noticeId));
    }


    /**
     * 修改通知公告
     */
    @ApiOperation("通知公告-未读变已读")
    // @PreAuthorize("system:notice:edit")
    @Log(title = "修改已读", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/{noticeId}")
    public AjaxResult edit(@PathVariable Long noticeId) {
        return toAjax(noticeService.updateNoticeRead(noticeId));
    }

}
